export default{
    init(){
        document.addEventListener('click',(e)=>{
            getXPath(e.target)
        })
    }
}
function getIndex(ele){
    let children = Array.from(ele.parentNode.children).filter(item=>
        item.tagName.toLocaleLowerCase() === ele.tagName.toLocaleLowerCase()
        )
    for (let i = 0; i < children.length; i++) {
        if(ele === children[i]){
            return `[${i + 1}]`
        }
    }
    return null
}
function getXPath(ele){
    let currentEle = ele
    let xpath = ''
    while(currentEle !== document.body){
        xpath = currentEle.tagName.toLocaleLowerCase() + getIndex(currentEle) + xpath
        currentEle = currentEle.parentNode
    }
}

